let staticproperty = Symbol.for("staticproperty");

// 通过静态函数，单例模式

//ES6类的静态方法（只能直接由类名调用的方法）：static getInstance
//ES6类的静态属性：直接挂载在类名上的方法，如：Db.instance()  本案用Symbol代替静态属性名 --> Person[staticproperty] 
const MyPerson = class Person {

    personName = "1"; // 实例属性
    personAge = "1"; // 实例属性
    static getInstance() {
        if (Person[staticproperty] != undefined) {
            return Person[staticproperty];
        }
        Person[staticproperty] = new Person();
        return Person[staticproperty];
    }

    constructor() {
        this.personName = "person_szq";
        this.personAge = "40";
        console.log(this.personName + ":" + this.personAge);

    }

};

// 通过构造函数，单例模式
const MyStudent = class Student {

    studentName = "1"; // 实例属性
    studentAge = "1"; // 实例属性
    constructor() {
        if (Student[staticproperty] == undefined) {
            this.studentName = "student_szq";
            this.studentAge = "20";
            console.log(this.studentName + ":" + this.studentAge);
            Student[staticproperty] = this;
        } else {
            return Student[staticproperty];
        }
    }

};

export { MyPerson, MyStudent };

